
// pages/my/my.js
let interval
var app = getApp(), api = require("../../api.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    itemList:[{
      imgUrl:'../../image/wallet-icon.png',
      text:'钱包',
      url:'./wallet/wallet'
    },{
      imgUrl:'../../image/order-icon.png',
      text:'订单',
      url:'../order/order'
    },{
      imgUrl:'../../image/invoice-icon.png',
      text:'发票',
      url:'./invoice/invoice'
    },{
      imgUrl:'../../image/cooper-icon.png',
      text:'合作',
      url:'./cooper/cooper'
    },{
      imgUrl:'../../image/help-icon.png',
      text:'帮助',
      url:'./help/help'
    },{
      imgUrl:'../../image/idea-icon.png',
      text:'意见反馈',
      url:'./idea/idea'
    },{
      imgUrl:'../../image/logo-icon.png',
      text:'关于云合',
      url:'../home/agree/agree'
    }],
    posLeft: 0,
    pace:1
  },
  roll: function (that, txtLength, windowWidth) {
    console.log(windowWidth)
    //return false;
    interval = setInterval(function () {
      if (-that.data.posLeft < windowWidth) {
        that.setData({
          posLeft: that.data.posLeft - that.data.pace,
          posLefts: that.data.posLeft - that.data.pace + windowWidth
        })
      } else {
        that.setData({
          posLeft: 0,
          posLefts: windowWidth
        })
      }
    }, 40)
  },
  goWallet: function(){
    wx.navigateTo({
      url: './wallet/wallet',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },
  clickList:function(e){
    let that = this
    let url = e.currentTarget.dataset.url
    if(url=='../order/order'){
      wx.switchTab({
        url:'../order/order'
      })
    }else{
      wx.navigateTo({
        url: url,
      })
    }
    
  },
  goTopUp:function(){
    wx.navigateTo({
      url: './topUp/topUp',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var _this=this;
    let that = this;
    wx.getSystemInfo({
      success: function success(res) {
        //转化成px
        var Wbox = res.windowWidth / 750 * 210;
        that.setData({
          Wbox: Wbox
        });
      }
    });
    let windowWidth = wx.getSystemInfoSync().windowWidth; //屏幕宽度
     app.request({
        url:api.my_info,
        method:'post',
        success:function(res){
            _this.setData({
              data:res.data
            })
          wx.createSelectorQuery().select('#txt').boundingClientRect(function (rect) {
            console.log(rect)
            that.roll(that, 3000, rect.width);
          }).exec()
        }
     })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    clearInterval(interval)
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    clearInterval(interval)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})